<%@page import="bean.User"%>
<%@page import="service.ArticleService"%>
<%@page import="bean.Article"%>
<%@page import="service.CategoryService"%>
<%@page import="java.io.IOException"%>
<%@page import="java.io.PrintWriter"%>
<%@page import="util.DataBaseUtils"%>
<%@page import="java.util.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	request.setCharacterEncoding("UTF-8");
	String header = request.getParameter("header");
	String name = request.getParameter("name");
	String content = request.getParameter("content");
	String categoryId = request.getParameter("categoryId");
	String description = request.getParameter("description");
	
	Article article = new Article();
	article.setId(UUID.randomUUID().toString());
	article.setHeader(header);
	article.setName(name);
	article.setContent(content);
	article.setCategoryId(categoryId);
	article.setIsDelete(0);
	article.setDescription(description);
	article.setCreateTime(new Date());
	article.setUpdateTime(new Date());
	article.setIsPublished(1);
	
	User user = (User)session.getAttribute("user");
	article.setAuthor(user.getUsername());
	article.setUserId(user.getId());
	
	String id = UUID.randomUUID().toString();
	ArticleService articleService = new ArticleService();
	articleService.addArticle(article);
	
	response.setCharacterEncoding("UTF-8");
	response.setContentType("text/html;charset=UTF-8");
	PrintWriter writer = null;
	try {
		writer = response.getWriter();
	} catch (IOException e) {
		e.printStackTrace();
	}
	writer.write("<script>location.href='article.jsp';</script>");
	writer.flush();

%>